package com.mr.dao.entity;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;

/**
 * @author Alex
 */
@MappedSuperclass
public class BaseEntity implements Entity {
	private static final long serialVersionUID = -2258368439443695870L;
	@Id
	@GeneratedValue(generator = "domainIdGenerator")
	@GenericGenerator(name = "domainIdGenerator", strategy = "uuid")
	private String id;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		return id.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj instanceof BaseEntity) {
			if (this.hashCode() == obj.hashCode()) {
				return true;
			}
			return new EqualsBuilder().append(id, ((BaseEntity) obj).id).isEquals();
		}
		return false;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE);
	}

}
